/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.upc.dew.sisrest.dao.hibernate;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import pe.edu.upc.dew.sisrest.dao.CategoriaDao;
import pe.edu.upc.dew.sisrest.model.Categoria;

@Repository
public class CategoriaDaoHibernate extends HibernateDaoSupport implements CategoriaDao {

    //Constructor
    @Autowired
    public CategoriaDaoHibernate(SessionFactory sessionFactory) {
        setSessionFactory(sessionFactory);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Categoria> obtenerCategorias() {
        List list = getHibernateTemplate().find(" from Categoria ");
        return list;
    }

   @Override
   public Categoria obtenerCategoriaById(String idCategoria) {
        Categoria categoria = getHibernateTemplate().get(Categoria.class, idCategoria);
	return categoria;
    }

    @Override
    public void grabarCategoria(Categoria objCat) {
        getHibernateTemplate().saveOrUpdate(objCat);
    }

    @Override
    public void eliminarCategoria(String sId) {
        Categoria objCat= obtenerCategoriaById(sId);
        getHibernateTemplate().delete(objCat);
    }
}
